<link href="asset/css/show.css" rel="stylesheet" type="text/css">
<script src="asset/js/cetak_excel.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("#periode").change(function(){
		var periode = $("#periode").val();
		if(periode == 1){
			document.getElementById('tgl1').disabled = false;
			document.getElementById('tgl2').disabled = false;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}
		else if(periode == 2){
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = false;
			document.getElementById('bln2').disabled = false;
		}else{
			document.getElementById('tgl1').disabled = true;
			document.getElementById('tgl2').disabled = true;
			document.getElementById('bln1').disabled = true;
			document.getElementById('bln2').disabled = true;
		}
	});
});
</script>
<?php
	$tgl = date("d");
	$bln = date("m");
	$thn = date("Y");
	
	$periode = $_POST['periode'];
	$tgl1 = $_POST['tgl1'];
	$tgl2 = $_POST['tgl2'];
	$bln1 = $_POST['bln1'];
	$bln2 = $_POST['bln2'];
	$thn1 = $_POST['thn1'];
	$thn2 = $_POST['thn2'];
	$jns = $_POST['jenis'];
	$wlyh = $_POST['wilayah'];
	$stts = $_POST['status'];
	$rs = $_POST['ppk'];
	$jns = $_POST['jenis'];
?>
<div id="tiga_ba">
	<div id="tiga_baa">Laporan Hasil Verifikasi </div>
	<div id="tiga_bab">
		
	</div>
	<div class="clear"></div>
</div>

<form method="post" action="utama.php?module=mod_laporan&view=verifikasi">
	<table style="margin-left: 5px;" border="0">
		<tr>
			<td width="75">Periode </td>
			<td width="300">
				<select name="periode" id="periode" class="input1">
					<?php
						if($periode == 1){
							$s1 = "selected";
						}else if($periode == 2){
							$p1 = "disabled";
							$s2 = "selected";
						}else{
							$p1 = "disabled";
							$p2 = "disabled";
							$s3 = "selected";
						}
					?>
					<option value="1" <?php echo $s1; ?>>Hari</option>
					<option value="2" <?php echo $s2; ?>>Bulan</option>
					<option value="3" <?php echo $s3; ?>>Tahun</option>
				</select>
			</td>
			<?php
				if($_SESSION['id_ppk'] == 0){
			?>
			<td>PPK</td>
			<td>
				<select name="ppk" id="ppk" class="input2">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$ppk = mysql_query("select id_ppk,nama from ppk order by nama");
						while($p = mysql_fetch_array($ppk)){
							if($rs == $p['id_ppk']){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$p[id_ppk] $s>$p[nama]</option>";
						}
					?>
				</select>
			</td>
			<?php
				}else{
					$ppk = mysql_query("select id_ppk,nama from ppk where id_ppk = $_SESSION[id_ppk]");
					$p = mysql_fetch_array($ppk);
					echo "<td>PPK</td>
						<td>
							<input type=hidden name=ppk id=ppk class=input2 value=$p[id_ppk]>
							$p[nama]
						</td>";
				}
			?>
		</tr>
		<tr>
			<td>Dari </td>
			<td>
				<select name="tgl1" id="tgl1" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl1 == ''){
								$s = "selected";
							}else if($i == $tgl1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln1" id="bln1" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln1 == ''){
								$s = "selected";
							}else if($i == $bln1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn1" id="thn1" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn1 == ''){
								$s = "selected";
							}else if($i == $thn1){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td width="75">Status</td>
			<td colspan="3">
				<select name="status" class="input2" id="status">
					<option value=""> - - Pilih Semua - - </option>
					<?php
						$status = mysql_query("select * from status order by id_status");
						while($s = mysql_fetch_array($status)){
							if($s['id_status'] == $stts){
								echo "<option value=$s[id_status] selected>$s[status]</option>";
							}else{
								echo "<option value=$s[id_status]>$s[status]</option>";
							}
						}
					?>
				</select>
			</td>
		</tr>
		<tr>
			<td align="center">Sampai</td>
			<td>
				<select name="tgl2" id="tgl2" class="input1" <?php echo $p1; ?>>
					<option value="">Tgl</option>
					<?php
						for($i=1;$i<=31;$i++){
							if($i == $tgl && $tgl2 == ''){
								$s = "selected";
							}else if($i == $tgl2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="bln2" id="bln2" class="input1" <?php echo $p2; ?>>
					<option value="">Bln</option>
					<?php
						for($i=1;$i<=12;$i++){
							if($i == $bln && $bln2 == ''){
								$s = "selected";
							}else if($i == $bln2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
				<select name="thn2" id="thn2" class="input1">
					<option value="">Thn</option>
					<?php
						for($i=2010;$i<=2020;$i++){
							if($i == $thn && $thn2 == ''){
								$s = "selected";
							}else if($i == $thn2){
								$s = "selected";
							}else{
								$s = "";
							}
							echo "<option value=$i $s>$i</option>";
						}
					?>
				</select>
			</td>
			<td>Jenis</td>
			<td>
				<select name="jenis" id="jenis" class="input2">
					<?php
						if($jns == 'inacbg'){
							$ss = "";
							$si = "selected";
						}else{
							$ss = "selected";
							$si = "";
						}
					?>
					<option value="service" <?php echo $ss; ?>>Fee For Service</option>
					<option value="inacbg" <?php echo $si; ?>>INA-CBG</option>
				</select>
			</td>
		</tr>
		<tr>
			<td></td>
			<td><input name="submit" id="proses" type="submit" class="button" value="Proses" /></td>
			<td></td>
			<td></td>
		</tr>
	</table>
</form>
<?php
	if($periode == 1){
		$tgl1 = "kl.tgl_trans >= '$thn1-$bln1-$tgl1'";
		$tgl2 = "and kl.tgl_trans <= '$thn2-$bln2-$tgl2'";
	}else if($periode == 2){
		$tgl1 = "kl.tgl_trans >= '$thn1-$bln1-01'";
		$tgl2 = "and kl.tgl_trans <= '$thn2-$bln2-31'";
	}else{
		$tgl1 = "kl.tgl_trans >= '$thn1-01-01'";
		$tgl2 = "and kl.tgl_trans <= '$thn2-12-31'";
	}
	
	if($stts != ''){
		$st = "and kl.id_status = '$stts'";
	}else{
		$st = "";
	}
	
	if($rs != ''){
		$id_rs = "and kl.id_ppk = '$rs'";
	}else{
		$id_rs = "";
	}
	
	if($_SESSION['id_jenis_pengguna'] == 5){
		$user = "and kl.id_verifikator = $_SESSION[id_pengguna]";
	}else{
		$user = "";
	}

	$query = "select pn.nama,kl.id_klaim,kl.tgl_trans,(YEAR(kl.tgl_trans) - YEAR(pn.tgl_lahir)) AS umur,s.status from klaim kl inner join peserta p on kl.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join status s on s.id_status = kl.id_status where $tgl1 $tgl2 $st $id_rs $user and jenis_klaim = '$jns' order by kl.tgl_trans";
	//echo $query;
	$qry1 = mysql_query($query);
	if($_POST['submit'] == 'Proses'){
	?>
		<div id="btnChart">
			<span id="print">
				<a href="#" class="export">
					<img src="asset/images/print.png" width="30">
				</a>
			</span>
		</div>
		<table class="tabel">
			<tr>
				<th rowspan="2">NO</th>
				<th rowspan="2">Nama Pasien</th>
				<th rowspan="2">Tanggal</th>
				<th rowspan="2">Umur</th>
				<th rowspan="2">Diagnosa</th>
				<th rowspan="2" width="75">Jumlah Tagihan Sebelum Verifikasi</th>
				<th colspan="2">Selisih Verifikasi</th>
				<th rowspan="2" width="75">Tagihan Setelah Verifikasi</th>
				<th rowspan="2">Status</th>
			</tr>
			<tr>
				<th>Kurang</th>
				<th>Lebih</th>
			</tr>
			<?php
				while($hasil = mysql_fetch_array($qry1)){
					$n++;
					if($jns == 'service'){
						$tarif=get_hitung_klaim($hasil['id_klaim']);
					}else{
						$tarif=get_hitung_inacbg($hasil['id_klaim']);
					}
					
					if($tarif['selisih'] >= 0){
						$lebih = $tarif['selisih'];
						$kurang = 0;
					}else {
						$kurang = str_replace("-","",$tarif['selisih']);
						$lebih = 0;
					}
			?>
					<tr>
						<td align="center"><?php echo $n ?></td>
						<td><?php echo $hasil['nama']; ?></td>
						<td align="center">
							<?php echo tgl_ind1($hasil['tgl_trans']); ?></td>
						<td align="center">
							<?php echo $hasil['umur']." th"; ?>
						</td>
						<td>
							<?php
								$diagnosis = mysql_query("select kl.icd10,m.keterangan from klaim_diagnosis kl inner join master_diagnosis m on kl.icd10 = m.icd10 where kl.id_klaim = '$hasil[id_klaim]'");
								while($d = mysql_fetch_array($diagnosis)){
									echo "<a title='$d[keterangan]'>$d[icd10]</a><br>";
								}
							?>
						</td>
						<td align="right">
							<?php echo format_angka($tarif['tarif_diminta']);?>
						</td>
						<td align="right">
							<?php echo format_angka($kurang);?>
						</td>
						<td align="right">
							<?php echo format_angka($lebih);?>
						</td>
						<td align="right">
							<?php echo format_angka($tarif['tarif_ditanggung']);?>
						</td>
						<td><?php echo $hasil['status']; ?></td>
					</tr>
			<?php	
					$total_diminta1 = $total_diminta1 + $tarif['tarif_diminta'];
					$total_ditanggung1 = $total_ditanggung1 + $tarif['tarif_ditanggung'];
					$total_kurang1 = $total_kurang1 + $kurang;
					$total_lebih1 = $total_lebih1 + $lebih;
				}
			?>
			<tr>
				<td colspan="5"><b>Total</b></td>
				<td align="right"><?php echo format_angka($total_diminta1);?></td>
				<td align="right"><?php echo format_angka($total_kurang1);?></td>
				<td align="right"><?php echo format_angka($total_lebih1);?></td>
				<td align="right"><?php echo format_angka($total_ditanggung1);?></td>
				<td></td>
			</tr>
		</table>
		<?php
		$query2 = "select pn.nama,kl.id_klaim,kl.tgl_trans,(YEAR(kl.tgl_trans) - YEAR(pn.tgl_lahir)) AS umur,s.status from klaim kl inner join peserta p on kl.id_peserta = p.id_peserta inner join penduduk pn on pn.id_penduduk = p.id_penduduk inner join status s on s.id_status = kl.id_status where $tgl1 $tgl2 $st $id_rs and jenis_klaim = '$jns' order by kl.tgl_trans";
		$qry2 = mysql_query($query2);
		?>
		<div id="dvData" style="display: none;">
			<table class="tabel">
				<tr>
					<th rowspan="2">NO</th>
					<th rowspan="2">Nama Pasien</th>
					<th rowspan="2">Tanggal</th>
					<th rowspan="2">Umur</th>
					<th rowspan="2">Diagnosa</th>
					<th rowspan="2" width="75">Jumlah Tagihan Sebelum Verifikasi</th>
					<th colspan="2">Selisih Verifikasi</th>
					<th rowspan="2" width="75">Tagihan Setelah Verifikasi</th>
					<th rowspan="2">Status</th>
				</tr>
				<tr>
					<th>Kurang</th>
					<th>Lebih</th>
				</tr>
				<?php
					while($hasil = mysql_fetch_array($qry2)){
						$no++;
						if($jns == 'service'){
							$tarif=get_hitung_klaim($hasil['id_klaim']);
						}else{
							$tarif=get_hitung_inacbg($hasil['id_klaim']);
						}
						if($tarif['selisih'] >= 0){
							$lebih = $tarif['selisih'];
							$kurang = 0;
						}else {
							$kurang = str_replace("-","",$tarif['selisih']);
							$lebih = 0;
						}
				?>
						<tr>
							<td align="center"><?php echo $no ?></td>
							<td><?php echo $hasil['nama']; ?></td>
							<td align="center">
								<?php echo tgl_ind1($hasil['tgl_trans']); ?></td>
							<td align="center">
								<?php echo $hasil['umur']." th"; ?>
							</td>
							<td>
								<table>
									<?php
										$diagnosis = mysql_query("select kl.icd10,m.keterangan from klaim_diagnosis kl inner join master_diagnosis m on kl.icd10 = m.icd10 where kl.id_klaim = '$hasil[id_klaim]'");
										while($d = mysql_fetch_array($diagnosis)){
											echo "<tr><td>$d[icd10]</td><td>$d[keterangan]</td></tr>";
										}
									?>
								</table>
							</td>
							<td align="right">
								<?php echo format_angka($tarif['tarif_diminta']);?>
							</td>
							<td align="right">
								<?php echo format_angka($kurang);?>
							</td>
							<td align="right">
								<?php echo format_angka($lebih);?>
							</td>
							<td align="right">
								<?php echo format_angka($tarif['tarif_ditanggung']);?>
							</td>
							<td><?php echo $hasil['status']; ?></td>
						</tr>
				<?php	
						$total_diminta2 = $total_diminta2 + $tarif['tarif_diminta'];
						$total_ditanggung2 = $total_ditanggung2 + $tarif['tarif_ditanggung'];
						$total_kurang2 = $total_kurang2 + $kurang;
						$total_lebih2 = $total_lebih2 + $lebih;
					}
				?>
				<tr>
					<td colspan="5"><b>Total</b></td>
					<td align="right"><?php echo format_angka($total_diminta2);?></td>
					<td align="right"><?php echo format_angka($total_kurang2);?></td>
					<td align="right"><?php echo format_angka($total_lebih2);?></td>
					<td align="right"><?php echo format_angka($total_ditanggung2);?></td>
					<td></td>
				</tr>
			</table>
		</div>
	<?php
	}
	?>
